<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <div class="timebox">
                <el-form-item label="名称" prop="labelName">
                  <el-input
                    v-model="queryParams.labelName"
                    class="w-100"
                    placeholder="请输入标签名称"
                  />
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="timebox">
                <el-form-item label="标签类型" prop="labelType">
                  <el-select
                    class="w-160"
                    v-model="queryParams.labelType"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in labelTypeList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>
    <div class="table_card">
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">门店标签</div>
        <div class="op_right">
          <button class="primary_button" @click="NewUser">新增标签</button>
        </div>
      </div>

      <div class="table_list">
        <el-table :data="StoreLabelList" stripe style="width: 100%">
          <el-table-column prop="labelSeq" label="标签排序"> </el-table-column>
          <el-table-column prop="labelName" label="标签名称"> </el-table-column>
          <el-table-column prop="labelType" label="标签类型">
            <template slot-scope="scope">
              {{ labelTypeObj[scope.row.labelType] }}
            </template>
          </el-table-column>
          <el-table-column prop="labelCode" label="标签编码"> </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="edit(scope.row)"
                >编辑</el-button
              >

              <el-button size="mini" type="text" @click="DelUser(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <!-- 新建门店标签 -->
      <el-dialog
        :visible.sync="categoryVisible"
        width="500px"
        :title="title"
        class="no-dialog-padding"
        @close="Canceluser"
      >
        <span>
          <div class="source_box">
            <el-form
              :model="CreateLabelForm"
              :rules="CreatecityRules"
              ref="CreateLabelForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item label="标签排序" prop="labelSeq">
                <el-input-number
                  v-model="CreateLabelForm.labelSeq"
                  :max="1000000"
                  :controls="false"
                  class="w-100 text-left"
                  :min="0"
                ></el-input-number>
              </el-form-item>
              <el-form-item label="标签名称" prop="labelName">
                <el-input v-model="CreateLabelForm.labelName"></el-input>
              </el-form-item>

              <el-form-item label="标签编码" prop="labelCode">
                <el-input
                  v-model="CreateLabelForm.labelCode"
                ></el-input>
              </el-form-item>

              <el-form-item label="标签类型" prop="labelType">
                <el-select
                  class="w-100"
                  v-model="CreateLabelForm.labelType"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in labelTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form>
          </div>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button class="cancel_btn" @click="Canceluser">取 消</el-button>
          <el-button
            type="primary"
            @click="userSubmit"
            :loading="CreateClienLoading"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {
  getStoreLabel,
  CreateStoreLabel,
  UpdateStoreLabel,
  getStoreLabelInfo,
  DeleteStoreCity,
  getAllLabelsByType,
} from "@/api/business/storelabel";
export default {
  name: "EryuoaStoreLabel",
  data() {
    return {
      StoreLabelList: [], // 门店标签列表数据
      CreateLabelForm: {
        labelCode: "",
        labelName: "",
        labelType: "",
        labelSeq: "",
        labelId: "",
      },
      CreatecityRules: {
        labelCode: [{ required: true, message: "请输入城市编码" }],
        labelName: [{ required: true, message: "请输入城市名称" }],
        labelType: [{ required: true, message: "请选择标签类型" }],
        labelSeq: [{ required: true, message: "请输入排序" }],
      },
      labelTypeObj: {
        S: "门店",
        U: "技师",
      },
      labelTypeList: [
        {
          value: "S",
          label: "门店",
        },
        { value: "U", label: "技师" },
      ],
      categoryVisible: false, // 新增
      loading: false,
      title: "",
      total: 0,
      CreateClienLoading: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        labelCode: "",
        labelName: "",
        labelType: "",
      },
    };
  },

  created() {
    this.getList();
  },

  mounted() {},

  methods: {
    // 获取门店城市详情
    getCategorys(id) {
      getStoreLabelInfo({
        id: id,
      })
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.CreateLabelForm = data;
            this.CreateLabelForm.labelId = data.labelId;
          }
        })
        .catch((err) => {});
    },

    // 门店城市
    getList() {
      getStoreLabel(this.queryParams)
        .then((res) => {
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.StoreLabelList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    Canceluser() {
      this.resetFormData("CreateLabelForm");
      this.CreateClienLoading = false;
      this.$nextTick(() => {
        this.categoryVisible = false;
      });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.queryParams.categoryMoneyDay = "";
      this.queryParams.categoryMoneyMoon = "";
      this.handleQuery();
    },

    // 确定
    userSubmit() {
      this.$refs["CreateLabelForm"].validate((valid) => {
        if (valid) {
          if (!!this.CreateLabelForm.labelId) {
            this.UpdateCategorys();
          } else {
            this.CreateCategorys();
          }
        } else {
          return false;
        }
      });
    },

    // 新增
    CreateCategorys() {
      let CreateLabelForm = JSON.parse(JSON.stringify(this.CreateLabelForm));
      CreateLabelForm.labelId = this.CreateLabelForm.labelId;
      delete CreateLabelForm.labelId;
      CreateStoreLabel(CreateLabelForm)
        .then((res) => {
          const { code } = res;
          if (code === 0) {
            this.Canceluser();
            this.$message.success("操作成功");
            this.getList();
          }
        })
        .catch((err) => {});
    },

    // 编辑
    UpdateCategorys() {
      let CreateLabelForm = JSON.parse(JSON.stringify(this.CreateLabelForm));
      CreateLabelForm.labelId = this.CreateLabelForm.labelId;
      UpdateStoreLabel(CreateLabelForm)
        .then((res) => {
          const { code } = res;
          if (code === 0) {
            this.Canceluser();
            this.$message.success("操作成功");
            this.getList();
          }
        })
        .catch((err) => {});
    },

    // 新建标签
    NewUser() {
      this.categoryVisible = true;
      this.title = "新增标签";
      this.CreateLabelForm.labelId = "";
    },

    // 编辑
    edit(row) {
      this.categoryVisible = true;
      this.title = "编辑标签";
      this.getCategorys(row.labelId);
    },

    // 表单重置
    resetFormData(formName) {
      this.$refs[formName].resetFields();
    },

    // 删除标签
    DelUser(row) {
      this.$confirm("确认要删除该门店标签吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          DeleteStoreCity({ labelId: row.labelId })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.getList();
                this.$modal.msgSuccess("操作成功");
              }
            })
            .catch(() => {});
        })
        .catch(() => {});
    },
  },
};
</script>
        
<style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}
.source_box {
  margin: 10px 24px;
}
.ipt_left {
  padding-right: 25px;
}
</style>
        
      
      